(function () {
    var d = /^[0-9]{11}\s*$/;
    var g = /^[0-9]{1,4}\s*$/;
    var f = /^[0-9]{1,5}\s*$/;
    var e = /^[0-9]{1,10}\s*$/;
    var c = /^[0-9]{1,10}\s*$/;
    var b = /^[0-9]([0-9]|-){1,48}[0-9]\s*$/;
    var a = /^[0-9]([0-9]|-){1,18}[0-9]\s*$/;
    var l = /[^\u4E00-\u9FA5]+\s*$/;
    var j = /^[0-9]{1,50}\s*$/;
    var i = /^[1-9]\d*$/;
    var k = /^(([3-9]\d{2,})|([1-9]\d{3,}))(\.\d{1,2})?$/;
    
    var RV = window.RV = function () {
        if (typeof RV == "undefined") {
            return window;
        } else {
            return RV;
        }
    };
    RV.config = {};

    RV.init = function () {
        RV.config = {
            userName:false,
            password:false,
            confirmPassword:false,
            email:false
            };
    };
    RV.userNameV = function () {
        var value = $.trim($("#userName").val());
        if(!value){
        	alert("空");
            RV.config.userName = false;
            RV.showMessage("notice_userName","请输入用户名。","errorSml");
        }
        if (value.length < 6 || value.length > 20 || !/^[a-zA-Z0-9\-]+\s*$/.test(value)) {
            RV.config.userName = false;
            RV.showMessage("notice_userName", "用户名不符合要求。", "errorSml");
            return
        }
        var data = {userName:value};
        jQuery.ajax({type:"post", url:"/register/checkUserName", data:data, cache:false, complete:function (r) {
            var q = r.responseText;
            if (q === "true") {
                RV.config.userName = true;
                return
            } else {
                if (q === "false") {
                    RV.config.userName = false;
                    RV.showMessage("notice_userName", "用户名已存在。", "errorSml");
                    return
                }
            }
        }});
    };

    RV.passwordV = function () {
        var n = $("#password");
        var m = $.trim(n.val());
        if (!m) {
            RV.config.password = false;
            RV.showMessage("notice_password", "请输入密码。", "errorSml");
            return
        }
        if (m.length < 6 || m.length > 20 || !/^[a-zA-Z0-9_\-]+\s*$/.test(m)) {
            RV.config.password = false;
            RV.showMessage("notice_password", "密码不符合要求。", "errorSml");
            return
        }
        if (m === $.trim($("#userName").val())) {
            RV.config.password = false;
            RV.showMessage("notice_password", "密码不可与用户名相同。", "errorSml");
            return
        }
        if (!dup(m)) {
            RV.config.password = false;
            RV.showMessage("notice_password", "密码过于简单。", "errorSml");
            return
        }
        RV.config.password = true;
    };

    RV.confirmPasswordV = function () {
        var n = $("#confimPassword");
        var m = $.trim(n.val());
        if (!m) {
            RV.config.confirmPassword = false;
            RV.showMessage("notice_confirmPassword", "请输入确认密码。", "errorSml");
            return
        }
        if (m !== $.trim($("#password").val())) {
            RV.config.confirmPassword = false;
            RV.showMessage("notice_confirmPassword", "两次输入不一致,请重新输入。", "errorSml");
            return
        }
        RV.config.confirmPassword = true;
    };

    RV.userEmailV = function () {
        var p = $("#email");
        var o = $.trim(p.val());
        var n = $.trim($("#userId").val());
        if (!o) {
            RV.config.email = false;
            RV.showMessage("notice_email", "请输入邮箱。", "errorSml");
            return
        }
        if (!RV.email(o)) {
            RV.config.email = false;
            RV.showMessage("notice_email", "请输入有效的邮件地址。", "errorSml");
            return
        }
        var m = {email:o, userId:n};
        jQuery.ajax({type:"post", url:"/register/checkUserEmail", data:m, cache:false, complete:function (r) {
            var q = r.responseText;
            if (q === "true") {
                RV.config.email = true;
                return
            } else {
                if (q === "false") {
                    RV.config.email = false;
                    RV.showMessage("notice_email", "此邮件地址已存在。", "errorSml");
                    return
                }
            }
        }});
    };

    var dup = function (x) {
        var w = true;
        var m = /^\d+$/;
        var n = /^[a-zA-Z]+$/;
        if (m.test(x)) {
            var q = x.split(""), t = 1, u = 1;
            for (var p = 1;
                 p < q.length;
                 p++) {
                if (q[p] - q[p - 1] == 1) {
                    t++;
                }
                if (q[p] - q[p - 1] == 0) {
                    u++;
                }
            }
            if (t == q.length || u == q.length) {
                return false;
            }
        }
        if (n.test(x)) {
            var v = x.split(""), s = 1, r = 1;
            for (var o = 1;
                 o < v.length;
                 o++) {
                if (v[o].charCodeAt(0) - v[o - 1].charCodeAt(0) == 1) {
                    s++;
                }
                if (v[o].charCodeAt(0) - v[o - 1].charCodeAt(0) == 0) {
                    r++;
                }
            }
            if (s == v.length || r == v.length) {
                return false;
            }
        }
        return w;
    };
    RV.email = function (m) {
        return/^([a-zA-Z0-9_-])*([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]+)+)\s*$/i.test(m);
    };
    RV.showMessage = function (p, n, m) {
        var o = $("#" + p);
        o.html(n).attr("class", m).show();
    };
    RV.hideMessage = function (n) {
        var m = $("#" + n);
        if (typeof m == "undefined") {
            return
        }
        m.html("").hide();
    };
    
    RV.focus = function (o) {

    };
    RV.blur = function (o) {
        
    };

    RV.submit = function () {
        var p = $("#editForm");
        RV.userNameV();
        RV.passwordV();
        RV.confimPasswordV();
        RV.userEmailV();
        var canSubmit = true;
        $.each(RV.config, function (t, s) {
            if (s === false) {
            	canSubmit = false;
            }
        });
        $(".errorSml").each(function () {
            if ($(this).is(":visible")) {
            	canSubmit = false;
            }
        });
        if (canSubmit === true) {
            p.submit();
        }
    };


})();